
var Tree = $("#tree");
var JQERY = $;
var chartDataZW="";
var curParmas = '';
var _page_gxq_hongguan_hgjjInfo={
    tree:null,
    nodeId :null,
    //chart是否初始化
    columnInit:false,
    barInit:false,
    pieInit:false,
    //chart类型
    chartType:null,
    chartRenderAs:{},
    //行列转换
    changeType:0,
    //带有checkbox的tr
    trWithCheckbox:null,
    //转置状态
    transformationStatus:true,
    reportTypeText:3,
    //编辑框的默认数据
    editModalDataForText:new Array(),
    editModalDataForId:new Array(),
    getTableInfo:function(id,text){//获取数据信息
        var data = tableInfo;
        if(data.des != undefined){
            var infoTable = $("#infoTable");
            infoTable.children().remove();
            var thead =data.thead ;
            infoTable.append(thead);
            infoTable.append(data.tbody);
            $("#des").html(data.des.DES_);
            _page_gxq_hongguan_hgjjInfo.trWithCheckbox=data.trWithCheckbox;
            /*描述点击事件  */
            $("#infoTable tbody tr td a").each(function(){
                $(this).click(function(){
                    $("#caption").text($(this).attr("caption"));
                    $("#desInfo").text($(this).attr("des"));
                    $("#myModal").show();
                });
            });
            /*END  描述点击事件  */

            /* 设置第一列的列宽 */
            var length =0;
            $("#infoTable  tr  td:first-child").each(function(){
                var text = $(this).prop("innerText");
                var  tdLength = text.length;
                if(length<tdLength){
                    length = tdLength
                }
            });
            _page_gxq_hongguan_hgjjInfo.tdWidth =length*16;
            $("#infoTable  tr  td:first-child").each(function(){
                $(this).css("width",_page_gxq_hongguan_hgjjInfo.tdWidth);
            });
            $("#infoTable  tr  th").each(function(){
                $(this).css("width",_page_gxq_hongguan_hgjjInfo.tdWidth);
            });
            $("#infoTable").css("margin-left",_page_gxq_hongguan_hgjjInfo.tdWidth);
        }
    },
    getTreeChildren:function(id){//获取树节点
    },
    //显示chart
    showChart:function(type){
        _page_gxq_hongguan_hgjjInfo.chartType= type;
        /*给table加上复选框  */
        var tbody = $("#infoTable tbody");
        if(!_page_gxq_hongguan_hgjjInfo.chartInit){//如果chart未加载过
            if(tbody.html()!= " "){
                var count = 0;
                //遍历所有tr 初始选中效果
                tbody.children("tr").each(function(){
                    var td = $(this).children("td:first");
                    count++;
                    if(count<6&&type!='pieChart'){//选中5行
                        $(this).addClass("onCheck");
                        td.prepend("<input type='checkbox' name='zbTd' checked='checked' ></tdLength>");
                    }else if(count<2&&type=='pieChart'){//饼图选中一行
                        td.prepend("<input type='checkbox' name='zbTd' checked='checked' /> ");
                        $(this).addClass("onCheck");
                    }else{
                        $(this).removeClass("onCheck");
                        td.prepend("<input type='checkbox' name='zbTd' />");
                    }
                });

                //拼接checkbox行
                tbody.prepend(_page_gxq_hongguan_hgjjInfo.trWithCheckbox);
                //获取表头 并遍历th元素
                var tr = "<tr id='checkboxTrNew'><td></td>"
                $("#infoTable thead").children("tr").each(function(){
                    $(this).children("th").each(function(){
                        if($(this).index()!=0){
                            var text = $.trim($(this).text());
                            $("#checkboxTr").children("td").each(function(){
                                var code = $(this).children("input[type='checkbox']").attr("code");
                                if(text == $.trim(code)){
                                    tr= tr+"<td>"+($(this).html())+"</td>";
                                }
                            });
                        }
                    });
                });
                tr = tr + "</tr>";
                $("#checkboxTr").remove();
                tbody.prepend(tr);
            }
            _page_gxq_hongguan_hgjjInfo.chartInit=true;
        }else{//如果chart已经加载
            if(tbody.html()!= " "){
                var count = 0;
                tbody.children("tr").each(function(){
                    //获取第一列(带有复选框的列)
                    var td = $(this).children("td:first");
                    //获取复选框
                    var input = td.children("input:first");
                    count++;
                    //设置复选框选中状态
                    if(input != 'undefined'){
                        if(type=='pieChart'){
                            input.removeAttr("checked");
                            if(count==2){//只设置数据行第一行的选中状态
                                $(this).addClass("onCheck");
                                input.prop("checked",true);
                            }else{//移除tr的标记
                                $(this).removeClass("onCheck");
                            }
                        }
                    }

                });
            }
        }
        /* END 给table加上复选框  */

        /*设置复选框行的宽度  */
        $("#checkboxTrNew td:first-child").css("width",_page_gxq_hongguan_hgjjInfo.tdWidth)
        /*END 设置复选框行的宽度  */




        /*获取指标索引  */
        //指标第一列(带有复选框的列)

        $("input[name='zbTd']").each(function(){
            $(this).click(function(){
                var checkBox = $(this);
                //判断是否是PIE图形

                if(_page_gxq_hongguan_hgjjInfo.chartType=='pieChart'){
                    //获取整个tbody
                    //遍历并且获取复选框的选中状态
                    var count = 0;//计数器
                    tbody.children("tr").each(function(){
                        $(this).children("td").each(function(){
                            //获取第一列
                            if($(this).index()==0){
                                var checkStatus = $(this).children("input[type='checkbox']:first").prop("checked");
                                if(checkStatus){//如果选中
                                    count++;
                                }
                            }
                        });
                        //判断选中个数保证必须有一个选中
                        if(count==0){
                            checkBox.prop("checked","checked");
                        }else if(count >=1){//多个选中
                            $(this).children("td").each(function(){
                                //获取第一列
                                if($(this).index()==0){
                                    $(this).children("input[type='checkbox']:first").removeAttr("checked");

                                }else{
                                    $(this).removeClass("checkStyle");
                                    $(this).parent("tr").removeClass("onCheck");
                                }
                            });
                            checkBox.prop("checked","checked");
                        }

                    });
                }

                //获取复选框所在的tr
                var tr = $(this).parent().parent();
                //判断复选框是否选中
                if($(this).prop("checked")==true||$(this).prop("checked")=='checked'){
                    //给选中的tr添加标记
                    tr.addClass("onCheck");
                    var checkboxTr =  tbody.children("tr:first");//获取第一行数据(复选框)
                    //遍历复选框行的所有td
                    checkboxTr.children("td").each(function(){
                        //获取复选框
                        var checkbox = $(this).children("input");
                        //选中状态
                        var checked = checkbox.prop("checked");
                        var index = $(this).index();//获取td的索引位置
                        //遍历选中tr的td
                        tr.children("td").each(function(){
                            //设置对应第一行复选框选中的td样式
                            if(checked&&$(this).index()==index){
                                $(this).addClass("checkStyle");
                            }
                        });

                    });
                }else{
                    //移除标记
                    tr.removeClass("onCheck");
                    //移除所有选中状态
                    tr.children("td").each(function(){
                        $(this).removeClass("checkStyle");
                    });
                }
                //复选框选中事件
                if(_page_gxq_hongguan_hgjjInfo.chartInit){
                    /*  点击重置柱线状态*/
                    _page_gxq_hongguan_hgjjInfo.chartRenderAs={};
                    _page_gxq_hongguan_hgjjInfo.initChart(_page_gxq_hongguan_hgjjInfo.chartType,tbody);
                }
            });
            //_page_gxq_hongguan_hgjjInfo.initChart(type,tbody);
        });
        //日期(数据)列选中事件
        $("input[name='numTd']").each(function(){
            $(this).click(function(){
                var td = $(this).parent();
                var tr = td.parent();


                //如果选中
                if($(this).prop("checked")==true||$(this).prop("checked")=='checked'){
                    //遍历该元素后的所有同辈元素
                    tr.nextAll().each(function(){
                        //tr是否为选中(标记)状态
                        if($(this).prop('class').indexOf('onCheck')>-1){
                            //设置td选中效果
                            $(this).children().eq(td.index()).addClass("checkStyle");
                        }else{
                            //移除选中效果
                            $(this).children().eq(td.index()).removeClass("checkStyle");
                        }
                    });
                }else{//非选中
                    tr.nextAll().each(function(){
                        //移除选中效果
                        $(this).children().eq(td.index()).removeClass("checkStyle");
                    });
                }
                //复选框选中事件
                if(_page_gxq_hongguan_hgjjInfo.chartInit){
                    /*  点击重置柱线状态*/
                    _page_gxq_hongguan_hgjjInfo.chartRenderAs={};
                    _page_gxq_hongguan_hgjjInfo.initChart(_page_gxq_hongguan_hgjjInfo.chartType,tbody);
                }
            });

        });
        /*添加颜色样式  */
        if(tbody.html()!= " "){
            //遍历所有tr
            tbody.children("tr").each(function(){
                var tr = $(this);
                if($(this).index()==0){//获取第一行(有复选框的tr)
                    var td = $(this).children("td");//获取所有td
                    //遍历带有复选框的td
                    td.each(function(){
                        //获取复选框
                        var checkbox = $(this).children("input");
                        //获取复选框状态
                        var checked = checkbox.prop("checked");
                        var index = $(this).index();//获取td的索引位置
                        if(checked){//如果选中
                            tr.nextAll().each(function(){//遍历所有同辈元素
                                if(($(this).prop('class')).indexOf('onCheck')!=-1){//如果行被选中
                                    $(this).children().eq(index).addClass("checkStyle");
                                }else{
                                    $(this).children().eq(index).removeClass("checkStyle");
                                }
                            });
                        }else{//未选中
                            tr.nextAll().each(function(){
                                $(this).children().eq(index).removeClass("checkStyle");
                            });
                        }
                    });
                }
            });

        }
        /* END 添加颜色样式  */

        //显示chart
        _page_gxq_hongguan_hgjjInfo.initChart(_page_gxq_hongguan_hgjjInfo.chartType,tbody);
        $("#titleDiv").show();
    },
    //隐藏chart
    hideChart:function(){
        $("#chartDiv").hide();
        var tbody = $("#infoTable tbody");
        if(tbody.find("tr:first").attr("id")=="checkboxTrNew"){
            removeCheckbox(tbody,true);
        }
        _page_gxq_hongguan_hgjjInfo.chartType=null;
        _page_gxq_hongguan_hgjjInfo.chartInit=false;
        //设置树形宽度
        $("#tree").attr("style","overflow: auto;min-height:400px;height:"+$("div[class='col-sm-9 main']").height()+"px");
        $("#titleDiv").hide();
    },
    //初始化chart
    initChart:function(type,tbody){
        $("#chartDiv").show();
        //$("#chartDiv").children().remove();
        var chartData;
        var data =getSqlFromCheckColumnForBarReturnStr(tbody,_page_gxq_hongguan_hgjjInfo.changeType);
        chartData = chartDataZW;
        switch(type){
            //mscombidy2d
            case 'columnChart':
                var chartType = "mscombidy2d";//mscolumn2d

                var chart_column = new FusionCharts({
                    type: chartType,
                    width : "100%",
                    renderAt : "chartDiv",
                    dataFormat : "json",
                    dataSource :chartData

                }).render();

                _page_gxq_hongguan_hgjjInfo.chartInit=true;
                _page_gxq_hongguan_hgjjInfo.chartType="columnChart";
                break;
            case 'barChart' :
                var chart_bar = new FusionCharts({
                    type: "msbar2d",
                    width : "100%",
                    renderAt : "chartDiv",
                    dataFormat : "json",
                    dataSource :chartData
                }).render();
                _page_gxq_hongguan_hgjjInfo.chartInit=true;
                _page_gxq_hongguan_hgjjInfo.chartType="barChart";
                break;
            case 'pieChart' :
                var chart_pie = new FusionCharts({
                    type: "pie2d",
                    width : "100%",
                    renderAt : "chartDiv",
                    dataFormat : "json",
                    dataSource :chartData
                }).render();
                _page_gxq_hongguan_hgjjInfo.chartInit=true;
                _page_gxq_hongguan_hgjjInfo.chartType='pieChart';
                break;
        }
        //设置树形宽度
        $("#tree").attr("style","overflow: auto;min-height:400px;height:"+$("div[class='col-sm-9 main']").height()+"px");
    },
    /* 修改chart显示样式 */
    changeChart:function(){
        var curChartData = JSON.stringify(chartData_bar_ZW);
        curChartData = JSON.parse(curChartData);
        $("#editModalInfoDiv>table input:checked").each(function(index,value){
            // chartData_bar_ZW
            var attr = $(this)[0].getAttribute('value')
            if(attr ==='line'){
                curChartData.dataset[index].renderAs='line';
                curChartData.dataset[index].parentYAxis='S';
            }else{
                curChartData.dataset[index].renderAs='column';
                curChartData.dataset[index].parentYAxis='P'
            }
            chartDataZW = curChartData;
            $("#initChart_A").click();
        });
        $('#myEditModal').hide();
    }
    ,
    //导出EXCEL
    exportData:function(){
        //获取html内容
        $("#infoTableData").html($("#infoTable").find("tbody").html());
        var tbody = $("#infoTableData").find("tbody");
        //计数器
        var count=0;
        var jsonData = new Array();

        tbody.children("tr").each(function(){//移除样式  第一行td会有 一个 <!--6--
            var json = {};
            var key = 0;
            //如果chart已经初始化
            if(_page_gxq_hongguan_hgjjInfo.chartInit){
                //排除第一行
                if($(this).index()==0&&count==0){
                    //移除
                    $(this).remove();
                    //计数器加1
                    count++;
                }
            }

            $(this).removeAttr("class");
            $(this).removeAttr("style");
            $(this).children("td").each(function(){
                key++;
                //移除多于的数据
                $(this).removeAttr("class");
                $(this).removeAttr("style");
                $(this).children("a").remove();
                $(this).children("input").remove();
                json[key] =$(this).text();
            });
            jsonData.push(json);
        });
        jsonData.splice(0,1)

        params={
            filename:_page_gxq_hongguan_hgjjInfo.nodeText,
            excelHead:$("#infoTable").find("thead tr").html(),
            excelDatas:JSON.stringify(jsonData)
        }
        Bhl.exports.excelExport.exportData(params);
    },
    //去除空行空列
    removeBlank:function(){
        //获取tbody
        var  tbody = $("#infoTable").find("tbody");
        var trLength = tbody.children("tr").length;

        tbody.children("tr").each(function(){
            //行为空计数器
            var isBlankTr = 0;
            //获取td 元素并遍历
            $(this).children("td").each(function(){
                //排除第一列数据
                if($(this).index()>0){
                    //获取文本
                    var text = $(this).text();
                    //判断是否为空
                    if($.trim(text)!= ""){
                        //不为空计数器累加
                        isBlankTr++;
                    }
                }
            });
            //当前tr中td的text 属性 全部为""
            if(isBlankTr==0){
                //如果chart 已经初始化
                if(_page_gxq_hongguan_hgjjInfo.chartInit){
                    //排除第一行的chebox行(删除该行后chart会缺失数据)
                    if($(this).index()>0){
                        //移除元素
                        $(this).remove();
                    }
                }else{
                    //移除元素
                    $(this).remove();
                }
            }
        });

        //如果chart已经显示 不获取第一行tr
        var count = 0;
        //chart 初始化完毕
        if(_page_gxq_hongguan_hgjjInfo.chartInit){
            //计数器值 设置为1
            count=1;
        }
        //获取第一行带有数据的tr
        var tr = $("tbody tr").eq(count);
        //遍历所有TD
        tr.children("td").each(function(){
            //获取td的索引
            var index = $(this).index();
            //列为空计数器
            var isBlankTd = 0;

            if(index!= 0){//排除第一条数据
                var text = $(this).text();
                //如果无数据
                if(text == ""){
                    //获取下一个tr 不能超过tr的最大个数
                    if(count+1<=trLength){
                        var thead = $("#infoTable").find("thead").find("tr");
                        tbody.children("tr").each(function(){
                            var nextTr = $(this);
                            //获取tr的指定索引(对应上一个td)的td的文本
                            var text = nextTr.children("td").eq(index).text();
                            if($.trim(text)!=""){
                                //如果不为空累加
                                isBlankTd++;
                            }

                        });
                        if(isBlankTd==0){//如果某列数据全部为空
                            tbody.children("tr").each(function(){
                                var nextTr = $(this);
                                //取得指定的td
                                var td = nextTr.children("td").eq(index);
                                //添加标记 准备移除元素
                                td.addClass('remove');
                                //给表头追加标记
                                thead.children("th").eq(index).addClass('remove');
                            });
                        };
                    }
                }
            }
        });
        //移除带有remove的元素
        $("#infoTable").children().each(function(){
            $(this).children().each(function(){
                $(this).children().each(function(){
                    var attr = $(this).attr("class");
                    if(attr!=undefined){
                        //判断元素的class属性是否包含remove
                        if(attr!=undefined&&attr.match('remove')!= ""&&attr.match('remove')!= null){
                            //移除
                            $(this).remove();
                        }
                    }
                });

            });
        });
        //重新绘制chart
        if(_page_gxq_hongguan_hgjjInfo.chartInit){
            _page_gxq_hongguan_hgjjInfo.showChart(_page_gxq_hongguan_hgjjInfo.chartType);
        }
    },
    //转置
    transformation:function(){

        if(_page_gxq_hongguan_hgjjInfo.nodeId != null){
            $("#chartDiv").hide();
            _page_gxq_hongguan_hgjjInfo.chartInit=false;
            _page_gxq_hongguan_hgjjInfo.transformationStatus =! _page_gxq_hongguan_hgjjInfo.transformationStatus;
            _page_gxq_hongguan_hgjjInfo.getTableInfo(_page_gxq_hongguan_hgjjInfo.nodeId,_page_gxq_hongguan_hgjjInfo.nodeText)
        }

    },
    //恢复
    reback:function(){
        if(_page_gxq_hongguan_hgjjInfo.nodeId != null){
            $("#chartDiv").hide();
            _page_gxq_hongguan_hgjjInfo.chartInit=false;
            _page_gxq_hongguan_hgjjInfo.getTableInfo(_page_gxq_hongguan_hgjjInfo.nodeId,_page_gxq_hongguan_hgjjInfo.nodeText)
        }
    },
    /*获取树形节点*/
    getTreeData:function(level){
        $.ajax({
            url:"/app/macro/Types/11/Items?_method=GET&regionLevel=4&parid=0",
            type:"post",
            contentType: "application/json;charset=utf-8",
            dataType:"json",
            data:JSON.stringify([]),
            success:function(re){
                for(var i=0;i<re.length;i++){
                    re[i].text = re[i]['idenName'];
                    re[i].treeLevel = 0;
                    re[i].nodes=[];
                }
                _page_gxq_hongguan_hgjjInfo.tree=re;
            }
        })
    },
    /*END 获取树形节点*/
    /* 判断报告期 报表类型点击事件 */
    reportType:function(span,reportType){
        //样式设置
        $(".hongguan-main .hongguan-mainLeft span[class^='label']").each(function(){
            $(this).addClass('label-default');
            $(this).removeClass('label-info');
        });
        $(span).removeClass('label-default');
        $(span).addClass('label-info');
        //END 样式设置
        /*设置报告期  */
        _page_gxq_hongguan_hgjjInfo.reportTypeText = reportType;
        _page_gxq_hongguan_hgjjInfo.getTreeData();
    },
    /*END 判断报告期  */

    /*显示编辑设置框  */
    showEditModal:function(){
        /* 编辑模态框的DIV */
        var editModalInfoDiv = $("#editModalInfoDiv");
        /**拼接表格**/
        var html = "<table style='width:100%;'>";
        html+='<thead><tr><th>指标</th><th>柱</th><th>线</th></tr></thead>';
        html+='<tbody>'
        for(var i=0;i<chartDataZW.dataset.length;i++){
            html+='<tr>'
            html+='<td >'+chartDataZW.dataset[i].seriesName+'</td>';
            html+='<td ><input type="radio" name="'+chartDataZW.dataset[i].seriesName+'" value="'+'bar'+'" checked /></td>';
            html+='<td ><input type="radio" name="'+chartDataZW.dataset[i].seriesName+'"value="'+'line'+'" /></td>'
            html+='</tr>';
        }
        html+='</tbody>';
        html+='</table>';

        editModalInfoDiv.html(html);
        //初始化颜色选择组件
        for (var i = 0;i<_page_gxq_hongguan_hgjjInfo.editModalDataForId.length;i++){
            JQERY("#"+_page_gxq_hongguan_hgjjInfo.editModalDataForId[i]).spectrum({
                preferredFormat: "hex",//颜色格式
                showInput: true,
            });
        }
        //END  初始化颜色选择组件
        $("#myEditModal").show();
    },
    /*END 显示编辑设置框  */
    /* 关闭模态框 */
    closeModal:function(obj){
        if(obj ==undefined||obj==""){
            $('#myEditModal').hide();
        }else{
            var modal = obj.parentNode.parentNode.parentNode;
            $("#"+modal.id).hide();
        }
    }
    /*END 关闭模态框 */
};
$(function() {
    _page_gxq_hongguan_hgjjInfo.getTreeData();
    /* END 获取树形节点*/

});
$(document).ready(function(){
    /****图标点击时切换样式*****/
    iconClick()
    /****点击按钮时切回柱状图开始***/
    $('#bar_chart_zw').click(function(){
        chartDataZW = chartData_bar_ZW;
        $("#initChart_A").click();
    })
    /****点击按钮时切回柱状图结束***/
    /***默认时间类型***/
    // timeStep_zw
    initTimeSelect();
    /***树形节点初始化****/
    loadZTree(0,11);
    /**报表类型点击***/
    $('#time_type_zw>span').click(function(){
        $($('#time_type_zw>span')[0]).removeClass('label-info');
        $($('#time_type_zw>span')[0]).addClass('label-default')
        $($('#time_type_zw>span')[1]).removeClass('label-info');
        $($('#time_type_zw>span')[1]).addClass('label-default')
        $($('#time_type_zw>span')[2]).removeClass('label-info');
        $($('#time_type_zw>span')[2]).addClass('label-default')
        $($(this)[0]).addClass('label-info')
        loadZTree(0,$(this)[0].getAttribute('value'))
        initTimeSelect();//更改时间选择框
    })
    /**折线图切换*/
    $('#chline_zw').click(function(){
        formateLineData()
    })
    /**选择自定义时间*/
    $("#timeStepBegin_zw,#timeStepEnd_zw").change(function(){
        timeChangeSelect()
    })
})
function loadZTree(parid,time){
    $.ajax({
        url:"/app/macro/Types/"+ time +"/Items?_method=GET&regionLevel=4&parid=" + parid,
        type:"post",
        contentType: "application/json;charset=utf-8",
        dataType:"json",
        data:JSON.stringify([]),
        success:function(re){
            for(var i=0;i<re.length;i++){
                re[i].name = re[i]['idenName'];
                re[i].treeLevel = 0;
                re[i].children=[];
            }
            var zTreeObj = $.fn.zTree.init($("#treeDemo"), {
                view:{
                    showLine:false,
                    showIcon:false
                },
                check:{
                    enable:true,
                    radioType:'level',
                    nocheckInherit:false,
                    chkboxType:{
                        "Y": "", "N": "ps"
                    }
                },
                callback:{
                    onExpand:function(event,treeId,treeNode){
                        if(treeNode.children.length>=1){
                            return false;
                        }
                        $.ajax({
                            url: "/app/macro/Types/"+ time +"/Items?_method=GET&regionLevel=4&parid=" + (treeNode.matmid),
                            type: "post",
                            contentType: "application/json;charset=utf-8",
                            dataType: "json",
                            data: JSON.stringify([]),
                            success: function (re) {
                                for(var i=0;i<re.length;i++){
                                    re[i].name = re[i]['idenName'];
                                    re[i].treeLevel = 0;
                                    if(re[i].hasChild){
                                        re[i].children=[];
                                    }
                                }
                                var newNode = re;
                                var treeObj = $.fn.zTree.getZTreeObj("treeDemo");
                                var selectedNode = treeObj.getSelectedNodes();
                                treeObj.addNodes(treeNode, newNode);
                            }
                        })
                    },
                    beforeCheck:function(treeId,treeNode){
                        if(treeNode.hasChild){
                            return false;
                        }
                    },
                    onCheck:function(event, treeId, treeNode){
                        var treeObj = $.fn.zTree.getZTreeObj("treeDemo");
                        var nodes = treeObj.getCheckedNodes(true);
                        if(nodes.length<1){
                            chartData_bar_ZW.categories[0].category=[];
                            chartData_bar_ZW.dataset=[];
                            chartDataZW = chartData_bar_ZW;
                            $('#initChart_A').click();
                            $("#infoTable_zw").html('')
                            return;
                        };
                        var matmids=[];
                        nodes.forEach(function(item,index){
                            matmids.push(item.matmid)
                        })
                        var fromMonth = time ==11 ?0:$("#timeStepBegin_zw").val().slice(4,6);
                        var toMonth = time ==11 ?0:$("#timeStepEnd_zw").val().slice(4,6);
                        curParmas = {
                            matmids:matmids,
                            parid:treeNode.parid,
                            reportType:time
                        }
                        $.ajax({
                            url:'/app/macro/data/queryext?_method=GET',
                            type:'post',
                            contentType: "application/json;charset=utf-8",
                            dataType:"json",
                            data:JSON.stringify({
                            parid:treeNode.parid,
                                reportType:time,
                            timeRank:{
                            fromYear:$("#timeStepBegin_zw").val().slice(0,4),
                                toYear:$("#timeStepEnd_zw").val().slice(0,4),
                                fromMonth:fromMonth,
                                toMonth:toMonth
                        },
                            indicatorCodes:[],
                                catalog:12,//写死
                            regions:[{
                            regionCode:'4301##000000',
                            regionName:'无',
                            regionLevel:'4'
                        }],
                            matmids:matmids,
                            regionLevel:4,
                            idenCodes:''
                            }),
                            success:function(re){
                                if(re.content.length<1){
                                    SGIS.UI.alert("此期间没有数据！");
                                }
                                var infoTable = $("#infoTable_zw");
                                var html = '<thead><tr><th>指标</th>\t';
                                for(var i=0;i<re.periods.length;i++){
                                    html+='<th>';
                                    switch (time) {
                                        case '11' :
                                            html+=re.periods[i].year +'年';break;
                                        case 11 :
                                            html+=re.periods[i].year +'年';break;
                                        case '12':
                                            var season = re.periods[i].month === 13 ? '1':(
                                                re.periods[i].month === 14?'2':(
                                                    re.periods[i].month === 15?'3':'4'
                                                )
                                            )
                                            html+=re.periods[i].year +'年'
                                            + season +'季度';break;
                                        case '13': html+=re.periods[i].year +'年'+
                                            re.periods[i].month +'月份';break;
                                        default:;break;
                                    }
                                    // html+=re.head[i]
                                    html+='<\/th>\t';
                                }
                                html +='<\/tr><\/thead>'
                                html +='<tbody>'
                                for(var i=0;i<re.indicators.length;i++){
                                    html +='<tr>'
                                    html+="<td>" +
                                        re.indicators[i].idenName +'</td>'
                                    for(var m=2+i;m<re.content[0].length;m+=re.indicators.length){
                                        html +='<td style="background:#fff;padding:5px 10px">'
                                        var nu = Number(re.content[0][m])
                                        html +=nu?re.content[0][m]:'-';
                                        html +='<\/td>'
                                    }
                                    html +='<\/tr>'
                                }
                                html +='<\/tbody>'
                                infoTable.html(html)
                                /*图表数据格式化*/
                                    chartData_bar_ZW.categories[0].category=[];
                                    /*柱状图头部*/
                                    for(var i=0;i<re.periods.length;i++){
                                        switch (time) {
                                            case 11:
                                                var cc = re.periods[i].year +'年';
                                                chartData_bar_ZW.categories[0].category.push({
                                                    label:cc
                                                })
                                               break;
                                            case '11':
                                                var cc = re.periods[i].year +'年';
                                                chartData_bar_ZW.categories[0].category.push({
                                                    label:cc
                                                })
                                                break;
                                            case '12':
                                                var season = re.periods[i].month ==13?'第1':(
                                                    re.periods[i].month ==14?"第2":(
                                                        re.periods[i].month ==15?'第3':'第4'
                                                    )
                                                )
                                                var cc=re.periods[i].year +'年'
                                                + season +'季度';
                                                chartData_bar_ZW.categories[0].category.push({label:cc})
                                            break;
                                            case '13': var cc =re.periods[i].year +'年'+
                                                re.periods[i].month +'月份';
                                                chartData_bar_ZW.categories[0].category.push({
                                                    label:cc
                                                })
                                            break;
                                            default:break;
                                        }
                                        // html+=re.head[i]
                                        // html+='<\/th>\t';
                                    }
                                    chartData_bar_ZW.dataset =[];
                                    for(var i=0;i<re.indicators.length;i++){
                                        chartData_bar_ZW.dataset[i]={
                                            seriesName:re.indicators[i].idenName,
                                            data:[]
                                        };
                                        for(var m=2+i;m<re.content[0].length;m+=re.indicators.length){
                                            chartData_bar_ZW.dataset[i].data.push({value:Number(re.content[0][m])});
                                        }
                                    }
                                    chartDataZW = chartData_bar_ZW;
                                    $('#initChart_A').click();
                            }
                        })
                        // $("#initChart_A").click();
                        // _page_gxq_hongguan_hgjjInfo.getTableInfo(_page_gxq_hongguan_hgjjInfo.nodeId,'66')
                    }
                }
            }, re);
            setTimeout(function(){
                $('#treeDemo_1 #treeDemo_1_switch').trigger('click');
            },1000)
        }
    })
}
function formateLineData(){
    chartData_line_ZW.categories=chartData_bar_ZW.categories;
    var arr =JSON.stringify(chartData_bar_ZW.dataset);
    arr = JSON.parse(arr);
    for(var i=0;i<arr.length;i++){
        arr[i].renderAs="line"
        arr[i].parentYAxis="S"
    }
    chartData_line_ZW.dataset=arr;
    chartDataZW = chartData_line_ZW;
    $('#initChart_A').click();
}
function initTimeSelect(){
    var type =  $('#time_type_zw>span.label-info')[0].getAttribute('value');
    $.ajax({
        url:'/app/macro/data/findAllYear',
        type:'get',
        data:{
            reportType:type
        },
        success:function(re){
            var minYear = parseInt(re.maxAndMin[0].minYear);
            var maxYear = parseInt(re.maxAndMin[0].maxYear);
            if(type +''=='11'){
                // timeStepBegin_zw
                bhtml = '';
                ehtml = '';
                for (var i = minYear; i <= maxYear; i++) {
                    if(i!==maxYear){
                        bhtml += '<option value="' + i+'">' + i+ '</option>';
                        ehtml += '<option value="' + i+'">' + i+ '</option>';
                    }else{
                        bhtml += '<option value="' + i+'">' + i+ '</option>';
                        ehtml += '<option value="' + i+'" selected="selected">' + i+ '</option>';
                    }
                }
                $("#timeStepBegin_zw").html(bhtml);
                $("#timeStepEnd_zw").html(ehtml);
            }
            if(type +''=='12'){
                // timeStepBegin_zw
                var minMonth = parseInt(re.maxAndMin[0].minMOnth);
                var maxMonth = parseInt(re.maxAndMin[0].maxMonth);
                bhtml = '';
                ehtml = '';
                for (var i = minYear; i <= maxYear; i++) {
                    if(i!==maxYear){
                        for(var index=13;index<17;index++){
                            var season= index ===13?'1':(
                                index ===14?'2':(
                                    index ===15?'3':4
                                )
                            )
                            if(i==minYear){
                                if(index>=parseInt(minMonth)){
                                    bhtml += '<option value="' + i+index+'">' + i+'第'+season+'季度'+ '</option>';
                                    ehtml += '<option value="' + i+index+'">'  + i+'第'+season+'季度'+ '</option>';
                                }
                            }else{
                                bhtml += '<option value="' + i+index+'">' + i+'第'+season+'季度'+ '</option>';
                                ehtml += '<option value="' + i+index+'">'  + i+'第'+season+'季度'+ '</option>';
                            }
                        }
                    }else{
                        for(var index=13;index<17;index++) {
                            var season = index === 13 ? '1' : (
                                index === 14 ? '2' : (
                                    index === 15 ? '3' : 4
                                )
                            )
                            if(index<=maxMonth){
                                bhtml += '<option value="' + i+index+'">' + i+'第'+season+'季度'+ '</option>'
                                ehtml += '<option value="' + i+index+'" selected="selected">' + i+ '第'+season+'季度'+'</option>';

                            }
                        }
                    }
                }
                $("#timeStepBegin_zw").html(bhtml);
                $("#timeStepEnd_zw").html(ehtml);
            }
            if(type +''=='13'){
                // timeStepBegin_zw
                var minMonth = parseInt(re.maxAndMin[0].minMOnth);
                var maxMonth = parseInt(re.maxAndMin[0].maxMonth);
                bhtml = '';
                ehtml = '';
                for (var i = minYear; i <= maxYear; i++) {
                    if(i!==maxYear){
                       for(var key=1;key<=12;key++){
                           var month ='';
                           if(key<10){
                               month='0' +key;
                           }else{
                               month = key;
                           }
                           if(i==minYear){
                               if(key>=minMonth){
                                   bhtml += '<option value="' + i+ month+'">' + i +'年'+  month+'月'+'</option>';
                                   ehtml += '<option value="' + i+ month+'">' + i +'年'+  month+'月'+'</option>';
                               }
                           }else{
                               bhtml += '<option value="' + i+ month+'">' + i +'年'+  month+'月'+'</option>';
                               ehtml += '<option value="' + i+ month+'">' + i +'年'+  month+'月'+'</option>';
                           }

                       }
                    }else{
                        for(var key=1;key<=12;key++){
                            var month ='';
                            if(key<10){
                                month='0' +key
                            }else{
                                month = key
                            }
                            if(key<=maxMonth){
                                bhtml += '<option value="' + i+ month+'">' + i +'年'+  month+'月'+'</option>';
                                ehtml += '<option value="' + i+ month+'" selected="selected">' + i +'年'+  month+'月'+'</option>';
                            }
                        }
                    }
                }
                $("#timeStepBegin_zw").html(bhtml);
                $("#timeStepEnd_zw").html(ehtml);
            }
        }
    })
}
function timeChangeSelect(){
    var treeObj = $.fn.zTree.getZTreeObj("treeDemo");
    var nodes = treeObj.getCheckedNodes(true);
    if(curParmas && nodes.length){
        var fromMonth = curParmas.time ==11 ?0:$("#timeStepBegin_zw").val().slice(4,6);
        var toMonth = curParmas.time ==11 ?0:$("#timeStepEnd_zw").val().slice(4,6);
        $.ajax({
            url:'/app/macro/data/queryext?_method=GET',
            type:'post',
            contentType: "application/json;charset=utf-8",
            dataType:"json",
            data:JSON.stringify({
                parid:curParmas.parid,
                reportType:curParmas.time,
                timeRank:{
                    fromYear:$("#timeStepBegin_zw").val().slice(0,4),
                    toYear:$("#timeStepEnd_zw").val().slice(0,4),
                    fromMonth:fromMonth,
                    toMonth:toMonth
                },
                indicatorCodes:[],
                catalog:12,//写死
                regions:[{
                    regionCode:'4301##000000',
                    regionName:'无',
                    regionLevel:'4'
                }],
                matmids:curParmas.matmids,
                regionLevel:4,
                idenCodes:''
            }),
            success:function(re){
                if(re.content.length<1){
                    SGIS.UI.alert("此期间没有数据！");
                }
                var infoTable = $("#infoTable_zw");
                var html = '<thead><tr><th>指标</th>\t';
                for(var i=0;i<re.periods.length;i++){
                    html+='<th>';
                    switch (re.periods[0].reportType) {
                        case '11' :
                            html+=re.periods[i].year +'年';break;
                        case 11 :
                            html+=re.periods[i].year +'年';break;
                        case 12:
                            var season = re.periods[i].month === 13 ? '1':(
                                re.periods[i].month === 14?'2':(
                                    re.periods[i].month === 15?'3':'4'
                                )
                            )
                            html+=re.periods[i].year +'年'
                                + season +'季度';break;
                        case 13: html+=re.periods[i].year +'年'+
                            re.periods[i].month +'月份';break;
                        default:;break;
                    }
                    // html+=re.head[i]
                    html+='<\/th>\t';
                }
                html +='<\/tr><\/thead>'
                html +='<tbody>'
                for(var i=0;i<re.indicators.length;i++){
                    html +='<tr>'
                    html+="<td>" +
                        re.indicators[i].idenName +'</td>'
                    for(var m=2+i;m<re.content[0].length;m+=re.indicators.length){
                        html +='<td style="background:#fff;padding:5px 10px">'
                        var nu = Number(re.content[0][m])
                        html +=nu?re.content[0][m]:'-';
                        html +='<\/td>'
                    }
                    html +='<\/tr>'
                }
                html +='<\/tbody>'
                infoTable.html(html)
                /*图表数据格式化*/
                chartData_bar_ZW.categories[0].category=[];
                /*柱状图头部*/
                for(var i=0;i<re.periods.length;i++){
                    switch (re.periods[0].reportType) {
                        case 11:
                            var cc = re.periods[i].year +'年';
                            chartData_bar_ZW.categories[0].category.push({
                                label:cc
                            })
                            break;
                        case '11':
                            var cc = re.periods[i].year +'年';
                            chartData_bar_ZW.categories[0].category.push({
                                label:cc
                            })
                            break;
                        case 12:
                            var season = re.periods[i].month ==13?'第1':(
                                re.periods[i].month ==14?"第2":(
                                    re.periods[i].month ==15?'第3':'第4'
                                )
                            )
                            var cc=re.periods[i].year +'年'
                            + season +'季度';
                            chartData_bar_ZW.categories[0].category.push({label:cc})
                            break;
                        case 13: var cc =re.periods[i].year +'年'+
                            re.periods[i].month +'月份';
                            chartData_bar_ZW.categories[0].category.push({
                                label:cc
                            })
                            break;
                        default:break;
                    }
                    // html+=re.head[i]
                    // html+='<\/th>\t';
                }
                chartData_bar_ZW.dataset =[];
                for(var i=0;i<re.indicators.length;i++){
                    chartData_bar_ZW.dataset[i]={
                        seriesName:re.indicators[i].idenName,
                        data:[]
                    };
                    for(var m=2+i;m<re.content[0].length;m+=re.indicators.length){
                        chartData_bar_ZW.dataset[i].data.push({value:Number(re.content[0][m])});
                    }
                }
                chartDataZW = chartData_bar_ZW;
                $('#initChart_A').click();
            }
        })
    }
}
/****图标点击时，切换样式**/
function iconClick(){
    // calc(100% - 410px)
    $('#infoDiv ul li:eq(0)').click(function () {
        $('.hongguan-mainTable')[0].style.height='calc(100%)';
    })
    $('#infoDiv ul>li:gt(0)').click(function () {
        $('.hongguan-mainTable')[0].style.height='calc(100% - 410px)';
    })
}